package com.example.springmvc.controller;

import com.example.springmvc.model.MessageInfo;
import com.example.springmvc.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
//存储留言信息
//   private List<MessageInfo> messageInfoList = new ArrayList<>();
    @Autowired
     private MessageInfoService messageInfoService;

    @RequestMapping(value = "/publish",method = RequestMethod.POST)
    public Boolean publish(@RequestBody MessageInfo messageInfo) {
        System.out.println("发表留言");
        //添加到数据库
        messageInfoService .insertMessage(messageInfo);
//        messageInfoList.add(messageInfo);
        return true;
    }

    @RequestMapping("/getList")
    public List getList() {
        //从数据库中查询
        return messageInfoService.queryMessage();
//        return messageInfoList;
    }
}
